﻿function SetCookie(name, value)
{
	var expdate = new Date();
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	if(expires!=null) expdate.setTime(expdate.getTime() + ( expires * 1000 ));
	document.cookie = name + "=" + escape (value) +((expires == null) ? "" : ("; expires="+ expdate.toGMTString()))+((path == null) ? "" : ("; path=" + path)) +((domain == null) ? "" : ("; domain=" + domain))+((secure == true) ? "; secure" : "");
}

var DomainUrl = "111ttt.com";
var AuthUrl = "jsu.111ttt.com";
//SetCookie("uuauth", "ok", null, "/", DomainUrl, false);
//document.write("<script language='javascript' src='http:\/\/" + AuthUrl + "\/getuuauthcode\/'><\/script>");

if(typeof(window.FMP) === "undefined") {
	var FMP = window.FMP = new (function(){
		var msie = /msie/.test(navigator.userAgent.toLowerCase());
		this.get = function(id) {
			var o = document.getElementById(id);
			if (!o || o.nodeName.toLowerCase() !== "object") {
				o = msie ? window[id] : document[id];
			}
			return o;
		};
		this.create = function(id, width, height, url, vars, params, attrs){
			var _attrs = {
				width : width,
				height : height,
				id : id
			};
			appendObj(_attrs, attrs);
			var _params = { 
				allowfullscreen : "true", 
				allowscriptaccess : "always" 
			};
			appendObj(_params, params);
			var _vars;
			if (vars) {
				if (typeof(vars) === "object") {
					var arr = [];
					for (var v in vars) {
						arr.push(v + "=" + encodeURIComponent(vars[v]));
					}
					_vars = arr.join("&");
				} else {
					_vars = vars + "";
				}
			}
			if (_vars) {
				_params.flashvars = _vars;
			}
			var htm = '<object ';
			if (msie) {
				htm += 'classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0" ';
			} else {
				htm += 'type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" data="'+url+'" ';
			}
			for (var a in _attrs) {
				htm += a + '="'+_attrs[a]+'" ';
			}
			htm += msie? '><param name="movie" value="'+url+'" />' : '>';
			for (var p in _params) {
				htm += '<param name="'+p+'" value="'+_params[p]+'" />';
			}
			htm += '<param name="wmode" value="transparent" />';
			htm += '</object>';
			return htm;
		};
		function appendObj(_obj, obj) {
			if (obj && typeof(obj) === "object") {
				for (var k in obj) {
					_obj[k] = obj[k];	
				}
			}
			return _obj;
		}
	})();
};

var urld = [];
var rnd = [];
var sTE = false;//是否可以添加新舞曲
var mode = 1; //0:顺序,1:随机;
var lastId = 0;

var player = {
	fmpObj:'',
	danceFile:'',
	fmp_loaded: function(key) {
		if(player.fmpObj) {
			player.fmpObj.addEventListener("model_state", "player.fmp_model_state");
		}
	},
	fmp_model_state: function(data) {//播放状态变换时调用
		//参数data就能返回当前播放状态
		if (data == "completed") {
			if(mode==1){
				playRnd();
			}
			else{
				play();
			}
		}
	},
	create: function(pId){
		var isiPad = navigator.userAgent.match(/iPad|iPhone|iPod/i) != null;
		if(isiPad){
			document.getElementById('loading').innerHTML = "由于iPad,iPhone,iPod设备不支持自动播放功能，所以您无法试听开场舞曲.";
		}
		else{
			var htm = FMP.create("fmp", "660", "24", "js/fplayer.swf", {api:"player.fmp_loaded",skin:"images/long.swf"});
			document.getElementById(pId).innerHTML = htm;
			player.fmpObj = FMP.get("fmp");
		}
	}
};

function START(){
	urld = [];
	rnd = [];
	lst = [];
	sTE = true;
}

function DATA(n, u, i){
	if(!sTE) return;
	urld[urld.length] = new dataClass(n, u, i);
}

function END(){
	var $loplist = $('#loplist');
	sTE = false;
	if(urld.length<1){
		urld[0] = new dataClass("列表为空", "", 0);
	}
	for(var ii=0; ii<urld.length; ii++){
		$loplist.append("<option value='" + ii + "' >" + (ii+1) + "." + urld[ii].name + "</option>");
	}
	$loplist[0].selectedIndex = 0;
	for(var ii=0; ii<urld.length; ii++){
		lst[ii] = ii;
	}

	if(mode==1){
		setTimeout("playRnd()", 2000);
	}
	else{
		setTimeout("play()", 2000);
	}
}

function dataClass(name, url, id){
	this.name = name;
	this.url = url.replace(/\\/g,"/");
	this.id = id;
}

function openfile(index){
	var $loplist = $('#loplist');
	$('#loplist')[0].selectedIndex = index;
	player.danceFile = urld[index].url;
	if(urld[index].id==1){
		player.fmpObj.list_xml('<list><m label="music" src="'+player.danceFile+'" type="2" /></list>', false);
		player.fmpObj.sendEvent('view_play');
		
	}
	else{
		player.fmpObj.list_xml('<list><m label="music" rtmp="rtmp://122.224.4.138:1935/dance/" src="'+player.danceFile+'" type="2" /></list>', false);
		player.fmpObj.sendEvent("view_play");
	}
}

function goToPlay(){
	$('#home').focus();
	var $loplist = $('#loplist');
	lastId = $loplist[0].selectedIndex+1;
	openfile($loplist[0].selectedIndex);
}

//顺序播放
function play(){
	if (lastId > lst.length-1)
	{openfile(0);}
	else
	{openfile(lastId++);}
}

//随机播放
function playRnd(){
	for(var ii=0; ii<urld.length; ii++){
		rnd[rnd.length++] = ii;
	}
	//alert(rnd);
	var rnum, firstNum;
	rnum = Math.floor(Math.random()*rnd.length);
	firstNum = rnd[rnum];
	lastId = firstNum+1;
	rnd[rnum] = rnd[rnd.length-1];
	rnd.length--;
	openfile(firstNum);
}
function onloadData(){
var movie = document.getElementById("fmp");
var nPercentLoaded = Math.abs(movie.PercentLoaded()); 
if(nPercentLoaded==100)  {
		setTimeout("$('#lodapl')[0].src = 'js/autoplaydata.asp';$('#loading').hide();", 1000);
}
else{
		setTimeout("onloadData()", 1000);
	}
}

function setMode(){
	if(mode==1){
		mode = 0;
		document.getElementById("mode").src="js/images/sx.png";
	}
	else{
		mode = 1;
		document.getElementById("mode").src="js/images/sj.png";
	}
}

window.onload = function(){
	onloadData();
	if(mode==1){
		document.getElementById("mode").src="js/images/sj.png";
	}
	else{
		document.getElementById("mode").src="js/images/sx.png";
	}
}
